package com.shuangfeidasan.controller.pms;

import com.shuangfeidasan.api.CommonPage;
import com.shuangfeidasan.api.CommonResult;
import com.shuangfeidasan.model.PmsCategory;
import com.shuangfeidasan.service.pms.PmsCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Description 产品表(PmsCategory)表控制层
 * @Author JunWEI
 * @Date 2022-03-22 22:09:51
 */
@Api(tags = "PmsCategoryController", description = "产品表(PmsCategory)")
@RestController
@RequestMapping("pmsCategory")
public class PmsCategoryController {
    @Autowired
    private PmsCategoryService pmsCategoryService;

    @ApiOperation("查询")
    @GetMapping("/list")
    public CommonResult queryAll(PmsCategory pmsCategory) {
        return CommonResult.success(this.pmsCategoryService.queryAll(pmsCategory));
    }

    @ApiOperation("通过主键查询单条数据")
    @GetMapping("{id}")
    public CommonResult queryById(@PathVariable("id") Long id) {
        return CommonResult.success(this.pmsCategoryService.queryById(id));
    }

    @ApiOperation("新增数据")
    @PostMapping
    public CommonResult add(@RequestBody PmsCategory pmsCategory) {
        return CommonResult.success(this.pmsCategoryService.insert(pmsCategory));
    }

    @ApiOperation("编辑数据")
    @PutMapping
    public CommonResult edit(@RequestBody PmsCategory pmsCategory) {
        return CommonResult.success(this.pmsCategoryService.update(pmsCategory));
    }

    @ApiOperation("删除数据")
    @DeleteMapping("/delete/{id}")
    public CommonResult deleteById(@PathVariable Long id) {
        return CommonResult.success(this.pmsCategoryService.deleteById(id));
    }
    
    @ApiOperation("分页查询")
    @GetMapping("/page")
    public CommonResult page(@RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize") Integer pageSize, PmsCategory pmsCategory) {
        PageHelper.startPage(currentPage,pageSize);
        List<PmsCategory> list = this.pmsCategoryService.queryAll(pmsCategory);
        return CommonResult.success(CommonPage.restPage(list));
    }
}
